package com.boot.ip;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.sql.SQLOutput;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author: lkz
 * @Title: SearchHttpAK
 * @Description: 百度AK
 * @Date: 2023/9/6 14:11
 */

public class SearchHttpAK {


    public static String URL = "https://api.map.baidu.com/location/ip?";

    public static String AK = "LXodkaI6BqWRtRGawXqiVaPrBkilBaOV";// 您的AK

    public static void main(String[] args) throws Exception {

        /**
         * 0 正常
         * 120 每秒请求量达到上限
         * 121 每日调用量已达到上限
         *
         */

        Map params = new LinkedHashMap<String, String>();
        params.put("ip", "180.111.120.254");
        params.put("coor", "bd09ll");
        params.put("ak", AK);

        String json = HttpUtil.get(URL, params);
        LocationVO locationVO = JSON.parseObject(json, LocationVO.class);
        LocationAddVO addressDetail = JSON.parseObject(JSON.toJSONString(locationVO.getContent().get("address_detail")), LocationAddVO.class);
        System.out.println(addressDetail);
        String address = (String)locationVO.getContent().get("address");
        System.out.println(address);

        System.out.println(locationVO);


    }


}


